﻿using System;
using UnityEditor;

internal class ProgressHelper
{
    internal float currentBuildStep;
    internal float numBuildSteps;

    public float Advance()
    {
        return (++this.currentBuildStep / this.numBuildSteps);
    }

    public float Get()
    {
        return (this.currentBuildStep / this.numBuildSteps);
    }

    public float LastValue()
    {
        return ((this.currentBuildStep - 1f) / this.numBuildSteps);
    }

    public void Reset(float numSteps)
    {
        this.currentBuildStep = 0f;
        this.numBuildSteps = numSteps;
    }

    public void Show(string title, string message)
    {
        if (EditorUtility.DisplayCancelableProgressBar(title, message, this.Get()))
        {
            throw new ProcessAbortedException("Creating staging area");
        }
    }

    public void Step(string title, string message)
    {
        this.Advance();
        this.Show(title, message);
    }
}

